<?php


namespace app\index\controller;

use think\Controller;
use think\Db;

class Data extends Controller
{
    public function index()
    {
        $result = Db::execute('insert into think_data (id, name ,status) values (6, "thinkphp", 1)');
        dump($result);
        $result = Db::execute('update think_data set name = "framework" where id = 6 ');
        dump($result);
        //读取（read）
        //  查询数据
        $result = Db::query('select * from think_data where id = 6');
        dump($result);
        // 删除数据
        $result = Db::execute('delete from think_data where id = 6 ');
        dump($result);
    }

    public function reg($id = '9999', $name = 'xk', $status = 1)
    {
        if ($id == '9999') {
            return '请输入id';
        }
        Db::execute('insert into think_data (id, name ,status) values (?, ?, ?)', [$id, $name, $status]);
        $result = Db::query('select * from think_data where id = ?', [$id]);
        dump($result);
    }

    public function reg2()
    {
        $list = Db::table('think_data')
            ->where('id', 1000)
            ->select();
//        $list2 = Db::name('data');
        dump($list);
        echo "<br/>";
        $list2 = db('data')->where('id', 1000)->select();
        dump($list2);
        //时间日期查询
        $result = Db::name('data')->whereTime('create_time', '>', '-2 days')->select();
        dump($result);
        // 获取今天的数据
        $result = Db::name('data') ->whereTime('create_time', 'today') ->select();
        dump($result);
        // 获取昨天的数据
        $result = Db::name('data') ->whereTime('create_time', 'yesterday') ->select();
        dump($result);
        //获取本周的数据
        $result = Db::name('data') ->whereTime('create_time', 'week') ->select();

    }
}